package project.base.common.util

import com.fasterxml.jackson.annotation.JsonInclude

/**
 * 封装响应结果
 * @author: 三味
 * @update: 2022/3/3 16:38
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
class ResponseResult<T>(
    private var success: Boolean, private var message: String?,
    private var code: Int?, private var data: T?, private var error: Throwable?
) {

    fun ResponseResult() {}

    fun isSuccess(): Boolean {
        return success
    }

    fun setSuccess(success: Boolean): ResponseResult<T> {
        this.success = success
        return this
    }

    fun getMessage(): String? {
        return message
    }

    fun setMessage(message: String?): ResponseResult<T> {
        this.message = message
        return this
    }

    fun getCode(): Int? {
        return code
    }

    fun setCode(code: Int?): ResponseResult<T> {
        this.code = code
        return this
    }

    fun getData(): T? {
        return data
    }

    fun setData(data: T?): ResponseResult<T> {
        this.data = data
        return this
    }

    fun getError(): Throwable? {
        return error
    }

    fun setError(error: Throwable?): ResponseResult<T> {
        this.error = error
        return this
    }

    override fun toString(): String {
        return "ResponseResult{" +
                "success=" + success +
                ", message='" + message + '\'' +
                ", code=" + code +
                ", data=" + data +
                ", error=" + error +
                '}'
    }
}
